<%@ page pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<jsp:include page="common/header.jsp"></jsp:include>


<h1><img src="${pageContext.request.contextPath}/views/images/icons/posts.png" alt="" /> 订单管理 </h1>
<div class="bloc">
	<div class="title">
  	订单管理（共计<font id="totalCount"> </font>个）
    </div>
	<div class="content dashboard">
	购买用户昵称&nbsp;&nbsp;<input id="buyUserName" name="buyUserName" style="width:156px" />
	&nbsp;&nbsp;&nbsp;&nbsp;订单号&nbsp;&nbsp;<input id="orderNum" name="orderNum" style="width:156px" />
	&nbsp;&nbsp;&nbsp;&nbsp;收件人姓名&nbsp;&nbsp;<input id="receiverName" name="receiverName" style="width:156px" />
	&nbsp;&nbsp;&nbsp;&nbsp;收件人电话&nbsp;&nbsp;<input id="receiverMobile" name="receiverMobile" style="width:156px" />
	<br><br>订单生成开始时间&nbsp;&nbsp;<input style="width:80px;" type="text" id="cstartdate" onfocus="reload97DatePicker(2);">
   	<input style="width:60px;" value="00:00:00" type="text" id="cstarttime" onfocus="reload97DatePicker(1);">
   	&nbsp;
	&nbsp;&nbsp;订单生成结束时间&nbsp;&nbsp;<input style="width:80px;" type="text" id="ccstartdate" onfocus="reload97DatePicker(2);">
   	<input style="width:60px;" value="00:00:00" type="text" id="ccstarttime" onfocus="reload97DatePicker(1);">
   	&nbsp;&nbsp;订单发货开始时间&nbsp;&nbsp;<input style="width:80px;" type="text" id="publishstartdate" onfocus="reload97DatePicker(2);">
   	<input style="width:60px;" value="00:00:00" type="text" id="publishstarttime" onfocus="reload97DatePicker(1);">
   	&nbsp;
	&nbsp;&nbsp;订单发货结束时间&nbsp;&nbsp;<input style="width:80px;" type="text" id="publishendstartdate" onfocus="reload97DatePicker(2);">
	<input style="width:60px;" value="00:00:00" type="text" id="publishendstarttime" onfocus="reload97DatePicker(1);">
	<br><br>订单支付开始时间&nbsp;&nbsp;<input style="width:80px;" type="text" id="paystartdate" onfocus="reload97DatePicker(2);">
   	<input style="width:60px;" value="00:00:00" type="text" id="paystarttime" onfocus="reload97DatePicker(1);">
   	&nbsp;
	&nbsp;&nbsp;订单支付结束时间&nbsp;&nbsp;<input style="width:80px;" type="text" id="payendstartdate" onfocus="reload97DatePicker(2);">
   	<input style="width:60px;" value="00:00:00" type="text" id="payendstarttime" onfocus="reload97DatePicker(1);">
   	&nbsp;&nbsp;订单退款开始时间&nbsp;&nbsp;<input style="width:80px;" type="text" id="refundstartdate" onfocus="reload97DatePicker(2);">
   	<input style="width:60px;" value="00:00:00" type="text" id="refundstarttime" onfocus="reload97DatePicker(1);">
   	&nbsp;
	&nbsp;&nbsp;订单退款结束时间&nbsp;&nbsp;<input style="width:80px;" type="text" id="refundendstartdate" onfocus="reload97DatePicker(2);">
   	<input style="width:60px;" value="00:00:00" type="text" id="refundendstarttime" onfocus="reload97DatePicker(1);">
	<br><br>订单取消开始时间&nbsp;&nbsp;<input style="width:80px;" type="text" id="cancelstartdate" onfocus="reload97DatePicker(2);">
   	<input style="width:60px;" value="00:00:00" type="text" id="cancelstarttime" onfocus="reload97DatePicker(1);">
   	&nbsp;
	&nbsp;&nbsp;订单取消结束时间&nbsp;&nbsp;<input style="width:80px;" type="text" id="cancelendstartdate" onfocus="reload97DatePicker(2);">
   	<input style="width:60px;" value="00:00:00" type="text" id="cancelendstarttime" onfocus="reload97DatePicker(1);">
   	&nbsp;&nbsp;用户签收开始时间&nbsp;&nbsp;<input style="width:80px;" type="text" id="signstartdate" onfocus="reload97DatePicker(2);">
   	<input style="width:60px;" value="00:00:00" type="text" id="signstarttime" onfocus="reload97DatePicker(1);">
   	&nbsp;
	&nbsp;&nbsp;用户签收结束时间&nbsp;&nbsp;<input style="width:80px;" type="text" id="signendstartdate" onfocus="reload97DatePicker(2);">
   	<input style="width:60px;" value="00:00:00" type="text" id="signendstarttime" onfocus="reload97DatePicker(1);">
	<br><br>
	订单状态&nbsp;&nbsp;
	<select id="status">
		<option value=''>请选择</option>
		<option value='0'>已删除</option>
		<option value='1'>已取消</option>
		<option value='2'>已过期</option>
		<option value='10'>正常单</option>
		<option value='11'>已完成未评论</option>
		<option value='99'>已完成已评论</option>
	</select>
	支付状态&nbsp;&nbsp;
	<select id="payStatus">
		<option value=''>请选择</option>
		<option value='0'>未支付</option>
		<option value='1'>已支付</option>
		<option value='10'>已退款</option>
	</select>
	快递状态&nbsp;&nbsp;
	<select id="expressStatus">
		<option value=''>请选择</option>
		<option value='0'>未发货</option>
		<option value='1'>已发货</option>
		<option value='99'>已签收</option>
	</select>
	支付类型&nbsp;&nbsp;
	<select id="payType">
		<option value='0' selected="selected">微信支付</option>
	</select>
	<br>
	&nbsp;&nbsp;&nbsp;&nbsp;配送单号&nbsp;&nbsp;<input id="expressNo" name="expressNo" style="width:156px" />
	&nbsp;&nbsp;&nbsp;&nbsp;配送公司&nbsp;&nbsp;<input id="expressCompanyName" name="expressCompanyName" style="width:156px" />
	&nbsp;&nbsp;&nbsp;&nbsp;按&nbsp;&nbsp;<select  id="colum" > 
				<option value="t.ctime" selected="selected">订单生成时间</option>	    	
				<option value="t.express_time">订单发货时间</option>	    	
				<option value="t.pay_time" >订单支付时间</option>	    	
				<option value="t.cancel_time">取消订单时间</option>	    	
				<option value="t.express_sign_time">用户签收时间</option>	    	
				<option value="t.refund_time">订单退款时间</option>	    	
			</select>
			  排序&nbsp;&nbsp;<select  id="order"> 
				<option value="asc">升序</option>
				<option value="desc"  selected="selected">降序</option>
		  </select>
		   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a id="button_search" class="mypage_button"> 查询</a>
	</div>
	<div class="content"  id="tableDiv" style="overflow-x:scroll">
        <table id="jgcsTable"  style="width:120%">
            <thead>
                <tr>
                    <th><input type="checkbox" class="checkall"/></th>
                    <th>序号</th>
						<th>id</th>
						<th>订单号</th>
						<th>状态</th>
						<th>运费</th>
						<th>优惠</th>
						<th>实际支付现金</th>
						<th>支付类型</th>
						<th>支付状态</th>
						<th>收件人</th>
						<th>收件人电话</th>
						<th>收件人纤细地址</th>
						<th>快递状态</th>
						<th>配送单号</th>
						<th>配送公司</th>
						<th>快递发货时间</th>
						<th>用户签收时间</th>
						<th>用户名称</th>
						<th>订单取消时间</th>
						<th>支付时间</th>
						<th>退款时间</th>
						<th>生成订单时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody id="tb_body">
            </tbody>
        </table>
    </div>
      <div id="kkpager"></div>
</div>
<script type="text/javascript">
var curPageName = "admin-gftgoodsorder";
changeCurrent();

$("#tableDiv").scroll(function(){//给table外面的div滚动事件绑定一个函数
	var left=$("#tableDiv").scrollLeft();//获取滚动的距离
	var trs=$("#tableDiv table tr");//获取表格的所有tr
	trs.each(function(i){//对每一个tr（每一行）进行处理
	//获得每一行下面的所有的td，然后选中下标为0的，即第一列，设置position为相对定位
	//相对于父div左边的距离为滑动的距离，然后设置个背景颜色，覆盖住后面几列数据滑动到第一列下面的情况
	//如果有必要也可以设置一个z-index属性
	$(this).children().eq(0).css({"position":"relative","top":"0px","left":left});
	$(this).children().eq(1).css({"position":"relative","top":"0px","left":left});
	$(this).children().eq(2).css({"position":"relative","top":"0px","left":left});
	$(this).children().eq(3).css({"position":"relative","top":"0px","left":left});
	});
}); 

$(function(){
	BindData(1);
});
// 查询按钮事件绑定
function bindSearch(){
	$('#button_search').unbind().bind('click',function(){
		BindData(1);
	});
} 


//AJAX方法取得数据并显示到页面上
function BindData(pageIndex) {
	//获取排序字段
	var orderStr = getOrderColum();
	var publishstartDate = getCTimeZone("publish");
	var publishendDate = getCTimeZone("publishend");
	var cancelDate = getCTimeZone("cancel");
	var cancelendDate = getCTimeZone("cancelend");
	var payDate = getCTimeZone("pay");
	var payendDate = getCTimeZone("payend");
	var refundDate = getCTimeZone("refund");
	var refundendDate = getCTimeZone("refundend");
	var cstartDate = getCTimeZone("c");
	var ccstartDate = getCTimeZone("cc");
	var signDate = getCTimeZone("sign");
	var signendDate = getCTimeZone("signend");
	$.ajax({
		type : "post", // 使用get方法访问后台
		dataType : "json", // 返回json格式的数据
		url : "${pageContext.request.contextPath}/admin-gftgoodsorder/ajaxdataList", // 要访问的后台地址
		data : {
			"orderStr":orderStr,
			"page" : pageIndex,
			"size":20,
			"ctimeStart":cstartDate.sartTime,
			"ctimeEnd":ccstartDate.sartTime,
			"refundTimeEnd":refundendDate.sartTime,
			"refundTimeStart":refundDate.sartTime,
			"payTimeEnd":payendDate.sartTime,
			"payTimeStart":payDate.sartTime,
			"cancelTimeEnd":cancelendDate.sartTime,
			"cancelTimeStart":cancelDate.sartTime,
			"expressSignTimeEnd":signendDate.sartTime,
			"expressSignTimeStart":signDate.sartTime,
			"expressTimeStart":publishstartDate.sartTime,
			"expressTimeEnd":publishendDate.sartTime,
			"buyUserName":$("#buyUserName").val(),
			"orderNum":$("#orderNum").val(),
			"payType":$("#payType").val(),
			"payStatus":$("#payStatus").val(),
			"receiverName":$("#receiverName").val(),
			"receiverMobile":$("#receiverMobile").val(),
			"status":$("#status").val(),
			"expressStatus":$("#expressStatus").val(),
			"expressCompanyName":$("#expressCompanyName").val(),
			"expressNo":$("#expressNo").val()
		}, // 要发送的数据
		ajaxStart : function() {
			$("#load").show();
		},
		complete : function() {
			$("#load").hide();
		}, // AJAX请求完成时隐藏loading提示
		success : function(msg) {// msg为返回的数据，在这里做数据绑定
			var data = msg.data;//列表数据
			var curPageIndex=msg.curPage;//当前页码
			var total=msg.total;//数据总条数
			$("#totalCount").text(total);
			var totalPage=msg.totalPage;//页面总数
			$("#tb_body").empty(); // 在读取数据时如果表格已存在行．一律删除
			var tmp = "";
			var ordNo = (curPageIndex-1)*20;//序号
			$.each(data,
					function(i, item) {
						ordNo++;
						var status = "";
						//状态：0 已删除，1 已取消，2 已过期，10 正常单，99 已完成
						if(item.status == 0){
							status = "已删除";
						}
						if(item.status == 1){
							status = "已取消";
						}
						if(item.status == 2){
							status = "已过期";
						}
						if(item.status == 10){
							status = "正常单";
						}
						if(item.status == 99){
							status = "已完成";
						}
						var payStatus = "";
						if(item.payStatus == 0){
							payStatus = "未付款";
						}
						if(item.payStatus == 1){
							payStatus = "已支付";
						}
						if(item.payStatus == 10){
							payStatus = "已退款";
						}
						var expressStatus = "";
						var expressDo = "";
						if(item.expressStatus == 0){
							expressStatus = "未发货";
							if(item.payStatus == 1){
								expressDo = "<a href='${pageContext.request.contextPath}/admin-gftgoodsorder/expressindex?id="+item.id+"' target='_parent' title='发货'>发货 </a>";
							}
						}
						if(item.expressStatus == 1){
							expressStatus = "已发货";
						}
						if(item.expressStatus == 99){
							expressStatus = "已签收";
						}
						var payType = "微信支付";
						if(item.payType == 1){
							payType = "其他快捷支付";
						}
						var ctime = "";
						if (item.ctime != null
								&& item.ctime != "") {
							ctime = new Date();
							ctime.setTime(item.ctime);
							ctime = ctime.Format('yyyy-MM-dd hh:mm:ss');

						}
						var refundTime = "";
						if (item.refundTime != null
								&& item.refundTime != "") {
							refundTime = new Date();
							refundTime.setTime(item.refundTime);
							refundTime = refundTime.Format('yyyy-MM-dd hh:mm:ss');

						}
						var cancelTime = "";
						if (item.cancelTime != null
								&& item.cancelTime != "") {
							cancelTime = new Date();
							cancelTime.setTime(item.cancelTime);
							cancelTime = cancelTime.Format('yyyy-MM-dd hh:mm:ss');

						}
						var payTime = "";
						if (item.payTime != null
								&& item.payTime != "") {
							payTime = new Date();
							payTime.setTime(item.payTime);
							payTime = payTime.Format('yyyy-MM-dd hh:mm:ss');

						}
						var expressSignTime = "";
						if (item.expressSignTime != null
								&& item.expressSignTime != "") {
							expressSignTime = new Date();
							expressSignTime.setTime(item.expressSignTime);
							expressSignTime = expressSignTime.Format('yyyy-MM-dd hh:mm:ss');

						}
						var expressTime = "";
						if (item.expressTime != null
								&& item.expressTime != "") {
							expressTime = new Date();
							expressTime.setTime(item.expressTime);
							expressTime = expressTime.Format('yyyy-MM-dd hh:mm:ss');

						}
						
						$("#jgcsTable").append(
												"<tr><td style='width:5%'><input type='checkbox' name='mailId' value='"+item.id+"'/></td><td style='width:5%'>" +
														+ ordNo + "</td>"
															+ "<td>" + item.id +  "</td>"
															+ "<td>" + item.orderNum +  "</td>"
															+ "<td>" + status +  "</td>"
															+ "<td>" + item.payExpress +  "</td>"
															+ "<td>" + item.payDiscount +  "</td>"
															+ "<td>" + item.payCash +  "</td>"
															+ "<td>" + payType +  "</td>"
															+ "<td>" + payStatus +  "</td>"
															+ "<td>" + (item.receiverName == null ? '' : item.receiverName) +  "</td>"
															+ "<td>" + item.receiverMobile +  "</td>"
															+ "<td>" + item.receiverAddress +  "</td>"
															+ "<td>" + expressStatus +  "</td>"
															+ "<td>" + (item.expressNo == null ? '' : item.expressNo) +  "</td>"
															+ "<td>" + (item.expressCompanyName == null ? '' : item.expressCompanyName) +  "</td>"
															+ "<td>" + expressTime +  "</td>"
															+ "<td>" + expressSignTime +  "</td>"
															+ "<td>" + item.buyUserName +  "</td>"
															+ "<td>" + cancelTime +  "</td>"
															+ "<td>" + payTime +  "</td>"
															+ "<td>" + refundTime +  "</td>"
															+ "<td>" + ctime +  "</td>"
														+ "<td>"
														+ " <a href='${pageContext.request.contextPath}/admin-gftgoodsorder/getinfo?id="+item.id+"' target='_parent' title='查看详情'>"
														+ "查看"
														+ "</a>&nbsp;&nbsp;"+ expressDo
														+ "</td></tr>");
			});
			generPageBar("BindData", curPageIndex, totalPage, total);
		},
		error : function() {
			var t = document.getElementById("tb_body"); // 获取展示数据的表格
			while (t.rows.length != 0) {
				t.removeChild(t.rows[0]); // 在读取数据时如果表格已存在行．一律删除
			}
			myAlert("加载数据失败");
		} 
	});
}

function batchDel(){
		var mailIds = '';
		$("input[name='mailId']:checked").each(function(){
			mailIds+=$(this).val()+',';
		});
		if( mailIds == ""){
			myAlert(" 请选择要删除的数据!");
			return;
		}
		myConfirm("确定要删除？", function(){
		$.ajax({
			url:"${pageContext.request.contextPath}/admin-gftgoodsorder/ajaxdelete",
			type: "POST",
			dataType: "text",
			data: {
				"ids":mailIds,
				"_":(new Date()).getTime()
			},
			success: function(rtn){
				var r = eval('('+ rtn +')');
				if(r.code == 0){
					myAlert("操作成功!");
					BindData(1);
				} else {
					myAlert(r.msg);
				}
			}
		})
		});
		
}

//获取排序字段
function getOrderColum() {
	var colum = $('#colum option:selected').val();
	if(colum != ""){
		var order = $('#order option:selected').val();
		return colum+" "+order;
	}
}

function getCTimeZone(fix) {
	var startdate = $("#"+fix+"startdate").val();
	var starttime = $("#"+fix+"starttime").val();
	
	var sartTime = "";
	if(startdate != ""){
		sartTime = startdate+" "+starttime;
	}
	
	var obj = {
			"startTime":sartTime
	}
	return obj;
}
</script>
